import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    menu: [],
    demoScrollTop: 0,
    isLoading: false,
    direction: 'forward',
    bodyHeiht: document.documentElement.clientHeight + 'px',
    orderType: '',
    type: '',
    serverID: '',
    childrenType: '',
    childrenTypeCount: 0,
    ssq: [],
    city: '',
    cityCode: '',
    cityCodeCount: 0,
    yjhj: 1,
    userInfo: {},
    startAddressInfo: {
      firstAddress: '正在获取当前位置...',
      detailsAddress: '',
      phone: '',
      lng: '',
      lat: '',
      province: '',
      city: '',
      area: '',
      provinceCityAreaName: ''
    },
    endAddressInfo: [
      {
        firstAddress: '',
        detailsAddress: '',
        phone: '',
        lng: '',
        lat: '',
        province: '',
        city: '',
        area: '',
        provinceCityAreaName: ''
      }
    ],
    endAddressInfo2: [{
      firstAddress: '',
      detailsAddress: '',
      phone: '',
      lng: '',
      lat: '',
      province: '',
      city: '',
      area: '',
      provinceCityAreaName: ''
    }]
  },
  getters: {
    getUserInfo (state) {
      return state.userInfo
    }
  },
  mutations: {
    updateDemoPosition (state, payload) {
      state.demoScrollTop = payload.top
    },
    updateLoadingStatus (state, payload) {
      state.isLoading = payload.isLoading
    },
    updateDirection (state, payload) {
      state.direction = payload.direction
    },
    setServerID (state, info) {
      state.serverID = info
    },
    setMenu (state, info) {
      state.menu = info
    },
    setType (state, info) {
      state.type = info
    },
    setOrderType (state, info) {
      state.orderType = info
    },
    setChildrenType (state, info) {
      state.childrenType = info
    },
    setChildrenTypeCount (state) {
      state.childrenTypeCount++
    },
    setCityCodeCount (state) {
      state.cityCodeCount++
    },
    setSSQ (state, info) {
      state.ssq = info
    },
    setCityCode (state, info) {
      state.cityCode = info
    },
    setYjhj (state, info) {
      state.yjhj = info
    },
    setCity (state, info) {
      state.city = info
    },
    setUserInfo (state, userInfo) {
      state.userInfo = userInfo
    },
    setStartAddress (state, addressInfo) {
      state.startAddressInfo = addressInfo
    },
    setEndAddress (state, addressInfo) {
      state.endAddressInfo = addressInfo
    },
    setEndAddress2 (state, addressInfo) {
      state.endAddressInfo2 = addressInfo
    }
  },
  actions: {
    updateDemoPosition ({commit}, top) {
      commit({type: 'updateDemoPosition', top: top})
    }
  }
})

export default store
